package com.yidu.qianfeng.controller;

import com.yidu.qianfeng.common.bean.check.Check;
import com.yidu.qianfeng.service.impl.CheckBizImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller("CheckController")
public class CheckController {
    @Resource(name = "checkBizImpl")
    private CheckBizImpl biz;

    public void setBiz(CheckBizImpl biz) {
        this.biz = biz;
    }

    @RequestMapping("/goAddcheck")
    public String goAddcheck(){
        return "views/yarding";
    }
    @RequestMapping("/goAddunloadscan")
    public String goAddunloadscan(){
        return "views/unloadscan";
    }
    @RequestMapping("/goAddtrucksequence")
    public String goAddtrucksequence(){
        return "views/trucksequence";
    }
    @RequestMapping("/goAddunloadsequence")
    public String goAddunloadsequence(){
        return "views/unloadsequence";
    }
    @RequestMapping("/goAddsignerlist")
    public String goAddsignerlist(){
        return "views/signerlist";
    }
    @RequestMapping("/goAdddeliverylist")
    public String goAdddeliverylist(){
        return "views/deliverylist";
    }
    @RequestMapping("/goAdddsigner")
    public String goAdddsigner(){
        return "views/signerscan";
    }
    @RequestMapping("/goAdddeliveryscan")
    public String goAdddeliveryscan(){
        return "views/deliveryscan";
    }

    /**
     * 扫码功能insertcheck新增一条数据
     * @param mid
     * @param timee
     * @return
     */
    @RequestMapping("/insertcheck")
    public String insertcheck(String mid ,String timee){
       //通过randomUUID获取uuid
        UUID uuid = UUID.randomUUID();
        //使用字符串str接收uuid
        String str = uuid.toString();
        //使用整数size接收核对数getcountCheck
        int size=biz.getcountCheck(mid);
        //使用整数count1接收核对数加1
        int count1=size+1;
        //使用模型check新增要扫码的数据
        Check check=new Check(str,mid,"er","fr","er","否","gh","vb","df",count1, timee,0,0,0);
        //使用整数count获取核对数insertcheck
        int count=biz.insertcheck(check);
        //使用整数update接收修改updatecheckcount是否成功
        int update=biz.updatecheckcount(check);


        return "index";
    }

    /**
     * 查询扫码getAllCheck中的所有数据
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/selectall")
    @ResponseBody
    public Map getAllCheck(int page, int limit){
        //使用list集合data接收查询的所有数据getAllCheck(page,limit)
        List<Check> data=biz.getAllCheck(page,limit);
        //使用整数count接收查询所有数据的条目数getallcheck
        int count=biz.getallcheck();
        //使用Map集合拼接json格式并将count放入“count”中
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }

    /**
     * 根据id删除扫码查询中的id
     * @param check_id
     * @param check_waybill_consign_num
     * @return
     */
    @RequestMapping("/deletecheck")
    public String deletecheck(String check_id ,String check_waybill_consign_num){
        //使用整数count接收deletecheck
        int count=biz.deletecheck(check_id);
        //使用整数check_count接收getcountCheck
        int check_count=biz.getcountCheck(check_waybill_consign_num);
        //使用整数update接收updatecheckcount1是否修改
        int update=biz.updatecheckcount1(check_waybill_consign_num,check_count);
        return "index";
    }

    /**
     * 根据托运单号查询扫码数据
     * @return
     */
    @RequestMapping("/selectone")
    @ResponseBody
    public Map selectallone(){
        //使用List<Check>集合data接收selectallone
        List<Check> data=biz.selectallone();
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }
    @RequestMapping("/getoneCheck")
    @ResponseBody
    public Map getoneCheck(String check_waybill_consign_num, int page, int limit){
        System.out.println("getoneCheck");
        List<Check> data=biz.getoneCheck(check_waybill_consign_num,page,limit);

        int count=biz.getcountCheck(check_waybill_consign_num);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }
    @RequestMapping("/updateload")

    public String updateload(String ids){
        System.out.println("updateload");
        String[] strs = ids.split(",");
        int[] idArray = new int[strs.length];
        for (int i = 0; i < strs.length; i++) {
            //把字符串数组转型后保存到整数数组里
            String check_car_loading="是";
            //调用逻辑层删除方法
            biz.updateload(strs[i],check_car_loading);
        }
        return "index";
    }

    /**
     * 使用动态sql语句查询数据
     * @param check_waybill_consign_num
     * @param check_car_loading
     * @param shipper_com
     * @param check_date
     * @param waybill_reach_city
     * @return
     */
    @RequestMapping("/selectallyuju")
    @ResponseBody
    public Map selectallyuju(String check_waybill_consign_num,String check_car_loading,String shipper_com,String check_date,String waybill_reach_city){
        //使用list<Check>集合接收selectallyuju
        List<Check> data=biz.selectallyuju(check_waybill_consign_num,check_car_loading,shipper_com,check_date,waybill_reach_city);
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }

    /**
     * 查询卸货扫码中的所有数据
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/getunloadCheck")
    @ResponseBody
    public Map getunloadCheck(int page, int limit){
        //使用List<Check>集合获取集合getunloadCheck中的所有数据
        List<Check> data=biz.getunloadCheck(page,limit);
        //使用整数count接收getallcheck1查询数据条目数
        int count=biz.getallcheck1();
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }

    /**
     * 新增一条卸货扫码的数据
     * @param mid
     * @param timee
     * @return
     */
    @RequestMapping("/insertunload")
    public String insertunload(String mid ,String timee){
        //使用randomUUID自动生成一条UUID并使用uuid接收
        UUID uuid = UUID.randomUUID();
        //将uuid转化成字符串并使用字符串str接收
        String str = uuid.toString();
        //使用整数size接收countunload
        int size=biz.countunload(mid);
        //初始核对数不能为0使用整数count接收size+1
        int count1=size+1;
        //使用模型check接收需要新增的值
        Check check=new Check(str,mid,"er","fr","er","否","gh","vb","df",0, timee,count1,0,0);
        //使用整数count接收insertcheck
        int count=biz.insertcheck(check);
        //使用整数update接收updatecheckcount2判断是否修改
        int update=biz.updatecheckcount2(check);
        return "index";
    }

    /**
     * 根据托运单号查询所需要的数据
     * @param check_waybill_consign_num
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/getoneCheck1")
    @ResponseBody
    public Map getoneCheck1(String check_waybill_consign_num, int page, int limit){
        //使用集合List<Check>接收getoneCheck1查询的数据
        List<Check> data=biz.getoneCheck1(check_waybill_consign_num,page,limit);
        //使用整数count接收countunload条目数
        int count=biz.countunload(check_waybill_consign_num);
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }

    /**
     * 删除卸货扫码中的数据
     * @param check_id
     * @param check_waybill_consign_num
     * @return
     */
    @RequestMapping("/deletecheck1")
    public String deletecheck1(String check_id ,String check_waybill_consign_num){
        //使用整数count接收deletecheck判断是否删除
        int count=biz.deletecheck(check_id);
        //使用整数check_count接收countunload获取核对数
        int check_count=biz.countunload(check_waybill_consign_num);
        //使用整数update接收updatecheckcount3修改核对数
        int update=biz.updatecheckcount3(check_count,check_waybill_consign_num);

        return "index";
    }

    /**
     * 查询卸货序列的所有数据
     * @return
     */
    @RequestMapping("/selectone1")
    @ResponseBody
    public Map selectallone1(){
        //使用集合 List<Check>接收selectallone1查询的所有数据
        List<Check> data=biz.selectallone1();
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }

    /**
     * 使用sql语句动态查询
     * @param check_waybill_consign_num
     * @param check_car_loading
     * @param shipper_com
     * @param check_date
     * @param waybill_reach_city
     * @return
     */
    @RequestMapping("/selectallyuju1")
    @ResponseBody
    public Map selectallyuju1(String check_waybill_consign_num,String check_car_loading,String shipper_com,String check_date,String waybill_reach_city){
        //使用集合List<Check>接收selectallyuju1查询所需要的数据
        List<Check> data=biz.selectallyuju1(check_waybill_consign_num,check_car_loading,shipper_com,check_date,waybill_reach_city);
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }

    /**
     * 新增派送扫码中的一条数据
     * @param mid
     * @param timee
     * @return
     */
    @RequestMapping("/insertdelivery")
    public String insertdelivery(String mid ,String timee){
        //使用randomUUID自动生成一条UUID并使用uuid接收
        UUID uuid = UUID.randomUUID();
        //使用字符串str接收uuid转换成字符串
        String str = uuid.toString();
        //使用整数size接收countdelivery
        int size=biz.countdelivery(mid);
        //使用整数count1接收size+1
        int count1=size+1;
        //使用模型Check接收要新增的值
        Check check=new Check(str,mid,"er","fr","er","否","gh","vb","df",0, timee,0,count1,0);
        int count=biz.insertcheck(check);
        int update=biz.updatedeliverycount(check);
        return "index";
    }

    /**
     * 查询派送扫码中的所有数据
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/getAlldelivery")
    @ResponseBody
    public Map getAlldelivery(int page, int limit){
        //使用集合List<Check>接收getAlldelivery查询的所有数据
        List<Check> data=biz.getAlldelivery(page,limit);
        //使用整数count接收getalldelivery查询的条目数
        int count=biz.getalldelivery();
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }

    /**
     * 根据托运单号查询所需要的数据
     * @param check_waybill_consign_num
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/getonedelivery")
    @ResponseBody
    public Map getonedelivery(String check_waybill_consign_num, int page, int limit){
        //使用集合 List<Check>接收getonedelivery查询的所有数据
        List<Check> data=biz.getonedelivery(check_waybill_consign_num,page,limit);
        //使用整数count接收countdelivery查询的条目数
        int count=biz.countdelivery(check_waybill_consign_num);
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }

    /**
     * 根据id删除派送扫码中的数据
     * @param check_id
     * @param check_waybill_consign_num
     * @return
     */
    @RequestMapping("/deletedelivery")
    public String deletedelivery(String check_id ,String check_waybill_consign_num){
        //使用整数count接收deletecheck判断是否删除
        int count=biz.deletecheck(check_id);
        //使用整数check_delivery_count接收countdelivery查询的条目数
        int check_delivery_count=biz.countdelivery(check_waybill_consign_num);
        //使用整数update接收updatedelivery判断是否修改
        int update=biz.updatedelivery(check_delivery_count,check_waybill_consign_num);

        return "index";
    }

    /**
     * 查询派送序列中的数据
     * @return
     */
    @RequestMapping("/selectdeliverylist")
    @ResponseBody
    public Map selectdeliverylist(){
        //使用集合List<Check>接收selectdelivery查询派送序列的所有数据
        List<Check> data=biz.selectdelivery();
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }

    /**
     * 使用动态sql语句查询派送序列的数据
     * @param check_waybill_consign_num
     * @param check_car_loading
     * @param shipper_com
     * @param check_date
     * @param waybill_reach_city
     * @return
     */
    @RequestMapping("/selectallyuju2")
    @ResponseBody
    public Map selectallyuju2(String check_waybill_consign_num,String check_car_loading,String shipper_com,String check_date,String waybill_reach_city){
        //使用集合List<Check>接收selectallyuju2查询的派送序列数据
        List<Check> data=biz.selectallyuju2(check_waybill_consign_num,check_car_loading,shipper_com,check_date,waybill_reach_city);
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }

    /**
     * 新增签收扫码中的一条数据
     * @param mid
     * @param timee
     * @return
     */
    @RequestMapping("/insertsigner")
    public String insertsigner(String mid ,String timee){
        //使用randomUUID自动生成一条UUID并使用uuid接收
        UUID uuid = UUID.randomUUID();
        //使用字符串str接收uuid转化为字符串
        String str = uuid.toString();
        //使用整数size接收countsigner查询的核对数
        int size=biz.countsigner(mid);
        //使用整数count1接收size+1
        int count1=size+1;
        //使用模型Check接收新增的值
        Check check=new Check(str,mid,"er","fr","er","否","gh","vb","df",0, timee,0,0,count1);
        //使用整数count接收insertcheck查询核对数
        int count=biz.insertcheck(check);
        //使用整数update接收updatesignercount判断是否修改
        int update=biz.updatesignercount(check);
        return "index";
    }
    @RequestMapping("/getAllsigner")
    @ResponseBody
    public Map getAllsigner(int page, int limit){
        System.out.println("getAllsigner");
        List<Check> data=biz.getAllsigner(page,limit);

        int count=biz.getallsigner();
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }

    /**
     * 根据托运单号查询签收扫码的数据
     * @param check_waybill_consign_num
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/getonesigner")
    @ResponseBody
    public Map getonesigner(String check_waybill_consign_num, int page, int limit){
        //使用集合List<Check>接收getonesigner查询的签收扫码中的数据
        List<Check> data=biz.getonesigner(check_waybill_consign_num,page,limit);
        //使用整数count接收countsigner查询的条目数
        int count=biz.countsigner(check_waybill_consign_num);
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",data);
        return map;
    }

    /**
     * 根据id删除签收扫码中的数据
     * @param check_id
     * @param check_waybill_consign_num
     * @return
     */
    @RequestMapping("/deletesigner")
    public String deletesigner(String check_id ,String check_waybill_consign_num){
        //使用整数count接收deletecheck是否删除成功
        int count=biz.deletecheck(check_id);
        //使用整数check_sign_count接收countsigner查询的核对数
        int check_sign_count=biz.countsigner(check_waybill_consign_num);
        //使用整数update接收updatedigner判断是否修改
        int update=biz.updatedigner(check_sign_count,check_waybill_consign_num);

        return "index";
    }

    /**
     * 查询签收序列的数据
     * @return
     */
    @RequestMapping("/selectsignerlist")
    @ResponseBody
    public Map selectsignerlist(){
        //使用集合List<Check>接收selectsigner查询的签收序列数据
        List<Check> data=biz.selectsigner();
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }

    /**
     * 使用动态sql语句查询签收序列的数据
     * @param check_waybill_consign_num
     * @param check_car_loading
     * @param shipper_com
     * @param check_date
     * @param waybill_reach_city
     * @return
     */
    @RequestMapping("/selectallyuju3")
    @ResponseBody
    public Map selectallyuju3(String check_waybill_consign_num,String check_car_loading,String shipper_com,String check_date,String waybill_reach_city){
        //使用集合List<Check>接收selectallyuju3查询签收序列的数据
        List<Check> data=biz.selectallyuju3(check_waybill_consign_num,check_car_loading,shipper_com,check_date,waybill_reach_city);
        //使用Map集合拼接json格式
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",0);
        map.put("data",data);
        return map;
    }
}
